<?php
/**
 * Created by novebeta.
 * Date: 10/21/12
 * Time: 11:36 AM
 */
$config_ui = '';
if (isset($config) && is_array($config)) {
    foreach ($config as $key => $value) {
        $config_ui .= "$key:$value;\n";
    }
}
app()->clientScript->registerCss(
    'acecss',
    "#editor {
            $config_ui
            position: relative;
    }"
);
Yii::app()->clientScript->registerScriptFile(
    Yii::app()->request->baseUrl . "/plugins/ace/ace.js",
    CClientScript::POS_HEAD);
?>
<div id="editor">
</div>
<input name="yt0" type="button" value="<?=$btnLabel;?>" id="yt0"/>
<script>
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/eclipse");
    editor.getSession().setMode("ace/mode/<?=$aceMode;?>");
    jQuery.ajax({'type':'post',
        'data':{
            'mode':'load',
        },
        'asyc':false,
        'success':function (data) {
            var dataval = JSON.parse(data);
            editor.setValue(dataval.<?=$attribute?>);
        }, 'url':'<?=Yii::app()->createUrl($urlPost)?>', 'cache':false});

    jQuery(function ($) {
        $('body').on('click', '#yt0', function () {
            jQuery.ajax({'type':'post',
                'data':{
                    'mode':'save',
                    '<?=$attribute?>':editor.getValue(),
                },
                'asyc':false,
                'success':function (data) {
                   window.location = '<?=Yii::app()->createUrl($urlPost)?>';
                }, 'url':'<?=Yii::app()->createUrl($urlPost)?>', 'cache':false});
            return false;
        });
    });
</script>